package rexsee.dialog;

import rexsee.core.browser.Browser;
import rexsee.core.menu.PopMenu;
import rexsee.core.widget.DivDialog;
import rexsee.core.widget.TabButtonRow;
import android.app.Activity;
import android.graphics.Color;
import android.view.KeyEvent;
import android.widget.LinearLayout;

public class ButtonDialog extends DivDialog {

	public ButtonDialog(Browser browser, String dialogId, String style, PopMenu[] menus) {
		super(browser, dialogId, style);
		try {
			LinearLayout layout = new LinearLayout(browser.getContext());
			layout.setOrientation(LinearLayout.VERTICAL);
			layout.setGravity(styleSheet.getGravity());
			layout.setBackgroundColor(Color.TRANSPARENT);
			for (int i = 0; i < menus.length; i++) {
				if (menus[i] != null) layout.addView(new TabButtonRow(browser.getContext(), menus[i]));
			}
			this.addChild(layout);
		} catch (Exception e) {
			browser.exception(this.getClass().getName(), e);
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (mBrowser.menu.isOptionsMenuOpen) {
				((Activity) mContext).closeOptionsMenu();
				return true;
			} else {
				if (styleSheet.window_cancelable.equalsIgnoreCase("true")) dismiss();
			}
		} else if (keyCode == KeyEvent.KEYCODE_MENU) {
			((Activity) mContext).openOptionsMenu();
		} else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_FOCUS) {
		} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
		} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
		} else {
		}
		return false;
	}

}
